package org.wzl._360mallbackend.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.wzl._360mallbackend.dao.ShoppingCartDao;
import org.wzl._360mallbackend.dto.ShoppingCartDTO;
import org.wzl._360mallbackend.service.ShoppingCartService;
import org.wzl._360mallbackend.utils.Response;

import java.util.List;

@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartDao shoppingCartDao;

    @Autowired
    private ShoppingCartService shoppingCartService;

    @GetMapping("/getByUserId")
    public Response getByUserId(Integer userId) {
        return Response.ok()
                .putData("shoppingCart" , shoppingCartService.getShoppingCartByUserId(userId));
    }

    @GetMapping("/add")
    public Response add(Integer commodityId, Integer userId) {
        shoppingCartService.addOneComodityShoppingCartById(commodityId, userId);
        return Response.ok();
    }

    @GetMapping("/delete")
    public Response delete(Integer id) {
        shoppingCartDao.deleteById(id);
        return Response.ok();
    }

}
